import java.lang.ref.SoftReference;
import java.util.LinkedList;
import java.util.List;

/**
 * 软引用测试：当进行完full gc后内存还是不够的时候会将软引用进行删除
 * @author: zyc
 */
public class SoftReferenceTest extends Object{

    private String flag = "";

    public static void main(String[] args) {
        List<Object> list = new LinkedList<>();
        Object       obj  = new Object();

        SoftReference<Object> sf = new SoftReference<>(obj);
        obj = null;
        while (true) {
            System.out.println(sf.get());
            list.add(new Object());
        }
    }


    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println("flag="+flag);
    }
}
